import {questionnaire} from '@/static/js/quickly/accomplishment/questionnaire.js';
import { getUrlParam} from '@/static/js/filter.js';
import member  from '@/components/selectMember/selectMember.vue';
export default{
	components:{member},
	data() {
		const currentDate = this.getDate({
			format: true
		})
		return {
			questionnaire:questionnaire,
			showModal: false,
			showContent: '',
			dialog: false,
			id: '',
			userName:'',
			start: '',
			end: currentDate,
			start_date:'',
			showModal1: false, //选择日期弹框组件
		}
	},
	onLoad() {},
	methods:{
		// 选答案
		answer(aitem,item) {
			const constArr = item.options.map((a) => {
				a.checked2 = false
				return a
			})
			aitem.checked2 = true			
		},
		
		//判断是否有未选择答案的问题
		determine() {
			const aa = this.questionnaire.map((a,ai) => {
				const bresult =  a.options.filter((b) => {
					return b.checked2
				})
				a.bresult = bresult
				return a
			})
			var aaArr = aa.filter((c,ci)=>{
				return c.bresult.length <= 0
			})
			if(aaArr.length > 0){
				this.showModal1 = true,
				this.showContent = '请选择'+aaArr[0].title
				return
			}
		},
		
		// 保存
		showModalbtn(e) {
			if(!this.userId) {
				uni.showToast({
					title:'请选择会员',
					icon:'none'
				})
				return
			}
			
			if(!this.start_date) {
				uni.showToast({
					title:'请选择日期',
					icon:'none'
				})
				return
			}
			this.determine()
		},
		Modalconfirm() {
			
		},
		//关闭弹出框
		hidedialog(){
			this.dialog = false
		},
		//选择会员
		chooseUser(e){
			this.userId = e.userId;
			this.userName = e.userName;
		},
		// 日期
		bindDateChange(e) { 
			this.start_date = e.target.value;
		},
		// 获取当前时间
		getDate(type) {
		   const date = new Date();
		   let year = date.getFullYear();
		   let month = date.getMonth() + 1;
		   let day = date.getDate();
		  
		   if (type === 'start') {
			year = year - 60;
		   } else if (type === 'end') {
			year = year + 2;
		   }
		   month = month > 9 ? month : '0' + month;;
		   day = day > 9 ? day : '0' + day;
		   return `${year}-${month}-${day}`;
		},
	}
}